// pages/index/components/shopResumeEdit/shopResume_edit.js

Component({
	/**
	 * 组件的属性列表
	 */
	properties: {
		trigger: {
			type: Boolean,
			default: false
		},
		myresumeEdit: Object
	},

	/**
	 * 组件的初始数据
	 */
	data: {
		deadlineDate:"2021-09-01",
		addressFieldTrigger: false,
		preferFieldTrigger: false,
		preferFieldTrigger: false,//tag
		preferList: ['高薪', '热门', '全职', '兼职', '职位多'],

		preferResult: [],

		// temp data
		title: '',
		wage:'',
		address: '',
		minContent : '',
		workInformation:'',
		workrequirements:'',
		prefer: [],
		numberRestrictions:0,
		
	},

	/**
	 * 组件的方法列表
	 */
	methods: {
		changeVar: function() {
			this.data.myresumeEdit.deadlineDate = this.data.deadlineDate
			this.data.myresumeEdit.title = this.data.title
			this.data.myresumeEdit.address = this.data.address
			this.data.myresumeEdit.wage = this.data.wage
			this.data.myresumeEdit.prefer = this.data.prefer
			this.data.myresumeEdit.minContent = this.data.minContent
			this.data.myresumeEdit.workInformation = this.data.workInformation
			this.data.myresumeEdit.workrequirements = this.data.workrequirements
			this.data.myresumeEdit.numberRestrictions = this.data.numberRestrictions
		},
		//保存按钮
		changePropTrigger: function(params) {
				this.changeVar() // 同页面调用函数
				this.triggerEvent('changeTriggerCpn',this.data.myresumeEdit)
		},
		// 触发picker
		changeFieldTrigger: function(e) {
			if (e.currentTarget.id == 'address') {
				this.setData({ // 改变视图层数据
					addressFieldTrigger: !this.data.addressFieldTrigger
				})
				let _this = this
				wx.chooseLocation({
					success: function (res) {
						console.log(res);
						_this.setData({
							address: res.address + res.name
						})
						
					},
					fail: function(res) {
						console.log("定位失败", res);
						wx.showToast({
							title: "定位失败",
							icon: 'error',
							duration: 2000
						  })
					}
				  })
			}else if (e.currentTarget.id == 'prefer') {
				this.setData({
					preferFieldTrigger: !this.data.preferFieldTrigger,
					// prefer: this.data.preferResult
				});
				if (this.data.preferFieldTrigger) {
					this.setData({
						arrow: 'arrow-down',
					})
				}else {
					this.setData({
						arrow: 'arrow',
					})
				}
			} else if (e.currentTarget.id == 'prefer-gp') {
				// console.log(e.detail);
				// console.log(e.currentTarget.id);
				// console.log(e);
				this.setData({
					preferResult: e.detail,
				})
				if (e.currentTarget.id == 'prefer-cell') {
					// 选中
					const { index } = e.currentTarget.dataset;
					// const checkbox = this.selectComponent(`.checkboxes-${index}`);
					const checkbox = this.selectAllComponents('.checkboxes-' + index)
					checkbox.toggle();
					console.log(checkbox);
				}
			}
		},

		bindDateChange: function (e) {
			this.setData({
				deadlineDate: e.detail.value
			})
		},

		changeNumberRestrictions: function (e) {
			this.setData({
				numberRestrictions: e.detail.value
			})
		},

		changeTitle: function(e) {
			this.setData({
				title: e.detail
			})
		},

		changeWage: function(e) {
			this.setData({
				wage: e.detail
			})
		},

		changeMinContent: function(e) {
			this.setData({
				minContent: e.detail
			})
		},

		changeWorkInformation: function(e) {
			this.setData({
				workInformation: e.detail
			})
		},

		changeWorkrequirements: function(e) {
			this.setData({
				workrequirements: e.detail
			})
		},

	},
	observers: {
		'preferResult': function(preferResult) {
			this.setData({
				prefer: preferResult
			})
		},
	},
	// 生命周期
	lifetimes: {
		attached: function() {
			this.setData({
				numberRestrictions: this.data.myresumeEdit.numberRestrictions,
				title: this.data.myresumeEdit.title,
				address: this.data.myresumeEdit.address,
				wage:this.data.myresumeEdit.wage,
				minContent:this.data.myresumeEdit.minContent,
				prefer: this.data.myresumeEdit.prefer,
				workInformation: this.data.myresumeEdit.workInformation,
				workrequirements: this.data.myresumeEdit.workrequirements,
				// deadlineDate: this.data.myresumeEdit.deadlineDate,
			});
			this.setData({
				preferResult: this.data.prefer
			})
		},
		detached: function() {
		}
	}
})
